{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="WAP_CSS/mill_common.css">
<style>
	.webuploader-element-invisible{
		opacity:0;
	}
</style>
{/block}

{block name="main"}
{php}
$member_detail 	   = api('System.Member.memberInfo');
$member_info  	   = $member_detail['data'];
//trace($member_info,"debug");
{/php}
<div class="main_content">
	{if condition="$member_info['user_info']['verify_status'] eq 0" }
		<div class="input-div">
			<span>真实姓名</span>
			<input type="text" id="real_name" placeholder="请输入您的真实姓名" value="{$member_info['user_info']['real_name']}">
		</div>
		<div class="line" style="height: 0px"></div>
		<div  class="input-div">
			<span>身份证号</span>
			<input type="text" id="id_number" placeholder="请输入您的身份证号码" value="{$member_info['user_info']['id_number']}">
		</div>
		<div class="input-div" style="margin-top: 20px">
			<span>身份证照片</span>
		</div>
		<div class="input-div" >
			<div class="id-number id_z  s-center">
				<img src="WAP_IMG/verify/id_z.jpg" class="lazy-load facepic" id="id_z_pre" data-url="{$id_z}">
			</div>

			<div class="id-number id_f  s-center">
				<img src="WAP_IMG/verify/id_f.jpg"  class="lazy-load facepic" id="id_f_pre" data-url="{$id_f}">
			</div>
			<div class="tip">请填写您的真实信息，通过后将不能修改</div>
		</div>
		<div class="input-div" style="margin-top: 20px;display: none">
			<span>支付宝收款码</span>
		</div>
		<div class="input-div" style="display: none">
			<div class="id-number ali_qr  s-center">
				<img src="WAP_IMG/verify/ali_qr.jpg"  class="lazy-load facepic" id="ali_qr_pre" data-url="{ali_qr}">
			</div>
			<div class="tip">请上传您的支付宝收款码，通过后将不能修改</div>
		</div>
		<div style="background-color: white;padding: 20px 20px;box-sizing: border-box">
			<button class="long-btn" onclick="act_modify()">立即认证</button>
		</div>
	{elseif condition="$member_info['user_info']['verify_status'] eq 1"}
	<link rel="stylesheet" href="WAP_CSS/notice_detail.css" />
		<div class="s-center" style="margin-top: 40%">
			<img src="WAP_IMG/verify/sh.png" style="width:80px " alt="">
		</div>
		<div style="text-align: center;margin-top: 20px;font-size: 16px">审核中，请您耐心等待</div>
	{else}
		<link rel="stylesheet" href="WAP_CSS/notice_detail.css" />
		<div class="s-center" style="margin-top: 40%">
			<img src="WAP_IMG/verify/shtg.png" style="width:80px " alt="">
		</div>
		<div style="text-align: center;margin-top: 20px;font-size: 16px;">审核已通过</div>
	{/if}
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__STATIC__/webuploader/webuploader.js"></script>
<script>
	$(function(){
		id_z = WebUploader.create({
			server: __URL(APPMAIN + '/member/uploadImage'),
			auto : false, // 选择文件的按钮。可选。// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: '.id_z',
			fileNumLimit: 1, // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false, // 只允许选择图片文件。
			accept: {
				title: 'Images',
				extensions: 'gif,jpg,jpeg,bmp,png',
				mimeTypes: 'image/*'
			},
			formData: {param: JSON.stringify({})},
			thumb: {width: 288,height: 160,crop: false}
		});
		// 当有文件被添加进队列的时候
		id_z.on('fileQueued', function (file) {
			curr_file = file;id_z.makeThumb(file, function (error, src) {
				if (error) {
					$("#id_z_pre").replaceWith('<span>不能预览</span>');
					return;
				}
				$("#id_z_pre").attr('src', src);
				id_z.upload()
			});
		});
		// 当上传成功的时候
		id_z.on('uploadSuccess', function (file, res) {
			if (curr_file) id_z.removeFile(curr_file);
			api('System.Member.modifyVerify', {'pic' : res.data,'qr' : 'id_z'}, function(res) {
				toast("上传成功！");
			}, false);

		});


		// 身份证反面
		id_f = WebUploader.create({
			server: __URL(APPMAIN + '/member/uploadImage'),
			auto : false, // 选择文件的按钮。可选。// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: '.id_f',
			fileNumLimit: 1, // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false, // 只允许选择图片文件。
			accept: {
				title: 'Images',
				extensions: 'gif,jpg,jpeg,bmp,png',
				mimeTypes: 'image/*'
			},
			formData: {param: JSON.stringify({})},
			thumb: {width: 288,height: 160,crop: false}
		});
		// 当有文件被添加进队列的时候
		id_f.on('fileQueued', function (file) {
			curr_file = file;id_f.makeThumb(file, function (error, src) {
				if (error) {
					$("#id_f_pre").replaceWith('<span>不能预览</span>');
					return;
				}
				$("#id_f_pre").attr('src', src);
				id_f.upload()
			});
		});
		// 当上传成功的时候
		id_f.on('uploadSuccess', function (file, res) {
			if (curr_file) id_f.removeFile(curr_file);
			api('System.Member.modifyVerify', {'pic' : res.data,'qr' : 'id_f'}, function(res) {
				toast("上传成功！");
			}, false);

		});


		// 支付宝 收款码
		ali_qr = WebUploader.create({
			server: __URL(APPMAIN + '/member/uploadImage'),
			auto : false, // 选择文件的按钮。可选。// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: '.ali_qr',
			fileNumLimit: 1, // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false, // 只允许选择图片文件。
			accept: {
				title: 'Images',
				extensions: 'gif,jpg,jpeg,bmp,png',
				mimeTypes: 'image/*'
			},
			formData: {param: JSON.stringify({})},
			thumb: {width: 288,height: 160,crop: false}
		});
		// 当有文件被添加进队列的时候
		ali_qr.on('fileQueued', function (file) {
			curr_file = file;ali_qr.makeThumb(file, function (error, src) {
				if (error) {
					$("#ali_qr_pre").replaceWith('<span>不能预览</span>');
					return;
				}
				$("#ali_qr_pre").attr('src', src);
				ali_qr.upload()
			});
		});
		// 当上传成功的时候
		ali_qr.on('uploadSuccess', function (file, res) {
			if (curr_file) ali_qr.removeFile(curr_file);
			api('System.Member.modifyVerify', {'pic' : res.data,'qr' : 'ali_qr'}, function(res) {
				toast("上传成功！");
			}, false);

		});


	});


	// 确认修改
	function act_modify() {
		//密码(6-16)位
		var id_z = $("#id_z_pre").attr("src");
		var id_f = $("#id_f_pre").attr("src");
		var real_name = $("#real_name").val();
		var id_number = $("#id_number").val();

		if (real_name.length < 2) {toast("请填写正确的真实姓名");return false;}
		if (id_number.length !== 15 && id_number.length !== 18) {toast("请填写正确的身份证号");return false;}

		if (id_z == '/template/wap/default/public/img/verify/id_z.jpg') {toast("身份证正面照片必须上传");return false;}
		if (id_f == '/template/wap/default/public/img/verify/id_f.jpg') {toast("身份证反面照片必须上传");return false;}

		api('System.Member.verifyID',
				{
					"real_name":real_name,
					"id_number":id_number,
					"id_z":id_z,
					"id_f":id_f,
				},
				function (res) {
					if (res.data > 0) {
						window.location.href = __URL(APPMAIN + "/index/index");
					} else if (res["message"] != null) {
						toast(res["message"]);
					}
				}
		)

	}
</script>
{/block}